package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.OrderSettingMapper;
import com.itheima.pojo.OrderDto;
import com.itheima.pojo.OrderSetting;
import com.itheima.utils.DateUtils;
import org.aspectj.weaver.ast.Or;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author cc
 * @Date 2021/8/18 22:36
 * @Version 1.0
 */
@Service
public class OrderSettingServiceImpl implements OrderSettingService {
    @Autowired
    private OrderSettingMapper orderSettingMapper;

    @Override
    public List<OrderDto> getOrderSettingByMonth(String currentDate) {
        final List<OrderSetting> orderSettings = this.orderSettingMapper.queryOrderSetting(currentDate);
        List<OrderDto> list = new ArrayList<>();
        for (OrderSetting orderSetting : orderSettings) {
            final OrderDto dto = new OrderDto();
            dto.setNum(orderSetting.getNumber());
            dto.setReservations(orderSetting.getReservations());
            try {
                final String s = DateUtils.parseDate2String(orderSetting.getOrderDate(), "yyyy-MM");
                final String[] split = s.split("-");
                final Integer day = Integer.valueOf(split[1]);
                dto.setDay(day);
            } catch (Exception e) {
                e.printStackTrace();
            }
            list.add(dto);
        }

        return list;
    }
}
